home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cgazv5n4.arc / EXCEPT.C < prev    next >
C/C++ Source or Header  |  1991-09-23  |  9KB  |  201 lines

  1. /*--- Listing 3 --------------------- EXCEPT.C -----------
  2.  * Exception processing for the hyphenation algorithm.
  3.  * Compiler:    Borland C/C++
  4.  * Author:      Allen I. Holub
  5.  *
  6.  * (C) 1988, 1991, Allen I. Holub. All rights reserved.
  7.  *-------------------------------------------------------*/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "hyphen.h"
  11.  
  12. /* All following words are exceptions to the hyphenation
  13.  * rules. The words in this list will also be recognized if 
  14.  * they are followed by an s or es.
  15.  */
  16.  
  17. static unsigned char *Hyexcept[] =
  18. {
  19.     "ab-sorb-ent",     "ac-cept-able",      "ac-ceptor",
  20.     "ac-cord-ance",    "ac-count-ant",      "ac-know-ledge",
  21.     "adapt-able",      "adapt-er",          "af-firm-a-tive",
  22.     "al-go-rithm",     "an-nouncer",        "ant-acid",
  23.     "ant-eater",       "ant-hill",          "an-tiq-uity",
  24.     "any-thing",       "apart-heid",        "arch-an-gel",
  25.     "arch-ery",        "ar-mi-stice",       "art-ist",
  26.     "askance",         "astig-ma-tism",     "astir",
  27.     "aston-ish-ment",  "at-mos-phere",      "bal-ding",
  28.     "bar-on-ess",      "beach-comber",      "beck-on",
  29.     "bes-tial",        "be-tween",          "bib-li-og-raphy",
  30.     "bind-ery",        "bi-no-mial",        "blast-off",
  31.     "board-er",        "bomb-er",           "bouncer",
  32.     "bound-ary",       "buff-er",           "bull-ish",
  33.     "buzz-er",         "by-stand-er",       "candle-stick",
  34.     "carb-on",         "cast-away",         "cast-off",
  35.     "cat-ion",         "cav-ern-ous",       "cen-ter",
  36.     "change-over",     "child-ish",         "chordal",
  37.     "civ-i-lize",      "class-ify",         "class-room",
  38.     "climb-er",        "clinch-er",
  39.     "coars-en",        "cognac",
  40.     "cole-slaw",       "com-a-tose",        "com-bat-ive",
  41.     "come-back",       "co-me-dian",        "com-men-da-tory",
  42.     "comp-troller",    "com-put-abil-ity",
  43.     "con-cat-e-nate",  "con-cat-e-na-tion"
  44.     "con-de-scend",    "cone-flower",
  45.     "con-form-ity",    "con-sult-ant",
  46.     "con-test-ant",    "con-trol-lable",    "co-nun-drum",
  47.     "con-vert-ible",   "co-star",           "count-ess",
  48.     "court-house",     "court-yard",        "cre-scendo",
  49.     "crest-fallen",    "cross-over",        "crypt-an-alysis",
  50.     "crys-tal-lize",   "curl-i-cue",        "damp-en",
  51.     "damp-est",        "dar-ling",          "debt-or",
  52.     "dec-la-ra-tion",  "de-cre-scendo",     "de-duct-ible",
  53.     "de-form-ity",     "de-gree",           "de-pend-able",
  54.     "de-pend-ent",     "de-scend-ent",      "de-scent",
  55.     "de-test-able",    "di-gest-ible",      "dis-cern-ible",
  56.     "dis-miss-al",     "dis-till-ery",      "dump-ling",
  57.     "earth-en-ware",   "east-ern",          "egg-head",
  58.     "egg-nog",         "eld-est",           "else-where",
  59.     "eq-uable",        "equipped",          "err-ing",
  60.     "es-tab-lish",     "eu-logy",           "eve-ning",
  61.     "every-thing",     "ex-ac-ti-tude",     "ex-ist-ence",
  62.     "ex-pend-able",    "ex-press-ible",     "fall-out",
  63.     "false-hood",      "far-thing",         "fencer",
  64.     "fiend-ish",       "for-eign-er",       "fore-short-en",
  65.     "fore-stall",      "found-ling",        "gen-er-ator",
  66.     "gold-en",         "handle-bar",        "hang-out",
  67.     "hang-over",       "hap-hazard",        "ha-rangue",
  68.     "hard-en",         "hard-ened",         "hard-est",
  69.     "harp-ist",        "haz-ard-ous",       "heart-ache",
  70.     "heart-ily",       "hence-forth",       "her-bal",
  71.     "hogs-head",       "hold-out",          "hold-over",
  72.     "hold-up",
  73.     "idler",           "im-mo-bi-lize",
  74.     "im-pass-able",    "im-per-turb-able",  "inch-worm",
  75.     "in-clem-ent",     "in-con-test-able",  "in-de-pend-ent",
  76.     "in-di-gest-ible", "ineq-uity",         "in-ex-acti-tude",
  77.     "in-ex-haust-ible","in-form-ant",       "iniq-uity",
  78.     "ink-blot",        "ink-ling",          "inn-keeper",
  79.     "in-sa-tiable",    "in-te-rior",        "in-ter-rupt-ible",
  80.     "ir-re-vers-ible", "jeop-ard-ize",      "kib-itzer",
  81.     "land-owner",      "launch-er",         "left-ist",
  82.     "left-over",       "less-en",           "life-style",
  83.     "lift-off",        "lime-stone",        "li-on-ess",
  84.     "liq-uefy",        "liq-uid",           "liq-ui-date",
  85.     "liq-ui-da-tion",  "liq-uor",           "live-stock",
  86.     "lull-aby",        "lunch-eon",         "lus-cious",
  87.     "main-spring",     "mast-head",         "me-ringue",
  88.     "me-ta-bo-lize",   "met-al",            "mile-stone",
  89.     "mince-meat",      "min-is-ter",        "min-is-try",
  90.     "mo-bi-lize",      "mod-ern-ize",       "mo-nop-o-lize",
  91.     "morgue",          "needle-work",       "neg-li-gible",
  92.     "ne-go-tiable",    "nerv-ous",          "nest-ling",
  93.     "non-con-form-ist","none-the-less",     "non-ex-ist-ent",
  94.     "non-metal",       "north-east",        "north-ern",
  95.     "nurse-maid",      "nurs-ery",          "ob-serv-able",
  96.     "ob-server",       "off-beat",          "off-hand",
  97.     "off-print",       "off-shoot",         "off-shore",
  98.     "off-spring",      "orange-ade",        "out-land-ish",
  99.     "pal-ate",         "pass-able",         "ped-a-gogy",
  100.     "pent-house",      "per-cent-age",      "pe-ri-odic",
  101.     "per-sist-ent",    "pet-al",            "pho-to-stat",
  102.     "play-thing",      "pleb-i-scite",      "plumb-er",
  103.     "poly-no-mial",    "port-hole",         "post-al",
  104.     "post-hu-mous",    "pre-dict-able",     "pre-req-ui-site",
  105.     "pre-school",      "pre-serv-ative",    "pre-vious",
  106.     "priest-hood",     "prob-abil-ity",     "prob-able",
  107.     "pro-ce-dure",     "pro-gram",          "pro-gram-mer",
  108.     "pro-grams",       "psalm-ist",         "pub-li-ca-tion",
  109.     "pub-lish",        "qua-drille",        "ranch-er",
  110.     "rattle-snake",    "re-corder",         "re-hears-al",
  111.     "rent-al",         "re-place-ment",     "rep-re-sent-a-tive",
  112.     "req-ui-si-tion",  "re-scind",          "re-search-er",
  113.     "re-solv-able",    "re-spect-able",     "re-start-ed",
  114.     "re-state-ment",   "re-store",          "re-vers-ible",
  115.     "re-volv-er",      "roll-away",         "round-about",
  116.     "sap-ling",        "sea-scape",         "self-ish",
  117.     "sell-out",        "send-off",          "sense-less",
  118.     "serv-er",         "serv-ice-able",     "sharpen",
  119.     "shoe-string",     "short-en",          "shy-ster",
  120.     "sib-ling",        "side-step",         "side-swipe",
  121.     "si-lencer",
  122.     "smoke-stack",
  123.     "snake-skin",      "so-ciable",         "soft-hearted",
  124.     "solv-able",       "som-er-sault",      "some-thing",
  125.     "sta-bi-lize",     "stand-ard-ize",     "stand-out",
  126.     "star-ling",       "stat-ure",          "ster-ling",
  127.     "stew-ard-ess",    "stiff-en",          "straight-for-ward",
  128.     "sub-se-quence",
  129.     "sug-gest-ible",   "su-pe-rior",        "surf-er",
  130.     "tan-ta-lize",     "thermo-stat",       "tongue",
  131.     "torque",          "toss-up",           "trench-ant",
  132.     "turn-about",      "turn-over",         "turn-table",
  133.     "ubiq-ui-tous",    "una-nim-ity",       "u-nan-i-mous",
  134.     "un-civ-i-lized",  "un-class-ified",    "un-con-trol-la-ble",
  135.     "unc-tuous",       "un-der-stand-able", "un-err-ing",
  136.     "un-gov-ern-able", "un-pre-dict-able",  "un-search-able",
  137.     "un-so-ciable",    "un-solv-able",      "up-swing",
  138.     "venge-ance",      "vict-ual",          "vignette",
  139.     "volt-age",        "wall-eye",          "waste-bas-ket",
  140.     "waste-land",      "watt-meter",        "weak-ling",
  141.     "west-ern-ize",    "when-ever",         "whisk-er",
  142.     "wors-en",         "yard-age",          "year-ling"
  143. };
  144. #define TABSIZE ( sizeof( Hyexcept ) / sizeof(char *) )
  145. /*--------------------------------------------------------*/
  146. static int wcmp( ctype *word, uchar **tabp )
  147. {
  148.     /* True is returned if the "word" matches but is followed
  149.      * by an 's' or 'es'. Note that the argument order is 
  150.      * correct, here for the bsearch() that is in the Borland 
  151.      * C/C++ run-time library: The key argument to bsearch() 
  152.      * is passed as the first argument to the comparison 
  153.      * function. You may have to swap the arguments for other 
  154.      * compilers' bsearch()s.
  155.      */
  156.  
  157.     uchar  *p;
  158.  
  159.     for(p = *tabp; *word && *p ; word++, p++ )
  160.     {
  161.         if( *p == '-' )
  162.             p++;
  163.         else if( CHAR(*word) != *p )
  164.             break;
  165.     }
  166.  
  167.     if( !*p  &&  (CHAR(word[0])=='s' ||
  168.                  (CHAR(word[0])=='e' && CHAR(word[1])=='s') ))
  169.         return 0;
  170.  
  171.     return( CHAR(*word) - *p );
  172. }
  173. /*--------------------------------------------------------*/
  174. int exception( ctype *word, ctype *end )
  175. {
  176.     /* Looks up word in the exception list and returns
  177.      * a pointer to the entry if it's there (0 if it
  178.      * isn't). Soft-hyphen points are added to the
  179.      * word before returning.
  180.      */
  181.  
  182.     uchar  **pp, *p;
  183.     int    rval = 0;
  184.     ctype  oend = *++end ;
  185.  
  186.     *end = 0;
  187.     pp = (uchar**)bsearch(word, Hyexcept, TABSIZE, sizeof(char*),
  188.                        (int(*)(const void*, const void*)) wcmp );
  189.     if(pp)
  190.     {
  191.         for(p = *pp ; *p ; word++, p++ )
  192.             if( *p == '-' )
  193.             {
  194.                 HYPHENATE( *word );
  195.                 p++;
  196.             }
  197.         rval = 1;
  198.     }
  199.     *end = oend;
  200.     return rval;
  201. }